<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Request;

class OthersController extends Controller
{
    public function _initialize()
    {   
        $finduser = db('user')->where('id',input('id'))->find();
        if(input('id') == input('session.user.id') || !$finduser){
            return abort(404,'页面不存在');
            
        }

        if(input('session.user.id')){
        	$userList = db('user')->where('id',input('session.user.id'))->find();
            $this->assign('userList', $userList);
        }

    	$ouserList = db('user')->where('id',input('id'))->find();
        $this->assign('ouserList', $ouserList);

        $opet = db('pet')->where('use_id',input('id'))->find();
        if($opet){
        	$this->assign('opet', $opet);
        }
        

        //动态
        $odongtai = Db::field('u.icon,u.nickname,d.dtime,d.caozuo,d.use_id,d.id')
        ->table('bbs_user u, bbs_dongtai d')
        ->where('u.id = d.use_id')
        ->where('d.use_id',input('id'))
        ->order('dtime','desc')
        ->select();
        $this->assign('odongtai',$odongtai);

        //关注
        $oguanzhu = db('friend')->where('use_id',input('session.user.id'))->where('fid',input('id'))->select();
        if($oguanzhu){
        	$this->assign('oguanzhu', $oguanzhu);
        }

        //统计数量
        $orizhi_num = count(db('rizhi')->where('use_id',input('id'))->select());
        $this->assign('orizhi_num',$orizhi_num);
        $oimg_num = count(db('img')->where('use_id',input('id'))->select());
        $this->assign('oimg_num',$oimg_num);  
        $oguanzhu_num = count(db('friend')->where('use_id',input('id'))->select());
        $this->assign('oguanzhu_num',$oguanzhu_num); 
        $ofensi_num = count(db('friend')->where('fid',input('id'))->select()); 
        $this->assign('ofensi_num',$ofensi_num);
 
        $ofriend_num = count(Db::query('select t1.* from (select * from bbs_friend where use_id = '.input('id').') as t1 inner join (select * from bbs_friend where fid = '.input('id').') as t2 on t1.fid = t2.use_id'));
        $this->assign('ofriend_num',$ofriend_num);

    	
    }
    

}